<?php
/**
 * Created by IDEA.
 * User: dinesh
 * Date: Mar 5, 2012
 * Time: 10:59:34 PM
 */

class SiteController extends BaseController {
    public $template = 'views';
    public $path = 'site';

    public function action() {
        // $this->urlRedirect("home") ;
        // $this->renderPartial('index');
        $this->actionLogin();
    }

    public function actionLogin() {
        $userId = $this->session->getSession('user_id');
        if (isset($_POST['submitted']) && !isset($userId)) {
            //if (isset($_POST['submitted']) ) {
            $loginModule = new Login();
            list ($check, $data) = $loginModule->checkLogin($_POST['username'], $_POST['password']);
            if ($check) { //successful user log in!
                $this->session->setData($data);
                $this->urlRedirect("home");

            } else { // Unsuccessful!  Assign $data to $errors for error reporting
                $message = $data;
                $this->renderPartial('login', array('MessageModel' => $message));
            }
        } else {
            $userId = $this->session->getSession('user_id');
            if (isset($userId)) { //check whether user already log in or not
                $this->urlRedirect('home');
            } else {
                $this->message = "this is contrller message";
                $this->renderPartial('login');
            }
        }

    }

    public function actionLogout() {
        $this->session->destroySession();
        $this->urlRedirect("site/login");
    }

    public function actionNoPage() {
        $this->render('noPage');
    }

}
